<?php
class tag extends Front {

    public function index( $c ) {

        if ( !$tag = R( 'tag' ) ) {
            $this->show_404();
        }

        $limit = empty( $this->setting[ 'article_num' ] ) ? 6 : $this->setting[ 'article_num' ];

        $tag = urldecode( $tag );
        $sql = "SELECT *
                FROM {$this->model->t('article')} AS c
                WHERE c.id
                IN (
                    SELECT b.aid
                    FROM {$this->model->t('tag')} AS a
                    LEFT JOIN {$this->model->t('mark')} AS b ON ( a.id = b.tid )
                WHERE a.tag = {$this->model->escape( $tag )}
                ) order by isTop desc, id desc";
        $result = $this->Pager( $limit )->findSql( $sql );

        $title = $tag;
        $keywords = $this->setting[ 'webkey' ];
        $description =  $this->setting[ 'webdesc' ];

        include $this->display( "index" );
    }
}